;
(function($, window, document, undefined) {
    var SNSExponent = function(el, opts) {
        this.el = el;
        this.defaults = {
            theme: 'macarons'
        };
        this.options = $.extend({}, this.defaults, opts);
    }

    SNSExponent.prototype = {
        init: function() {
            var me = this,
                el = me.el;

            if (el.attr('data-initialized') == 'true') {
                return me;
            }

            me.initChart();
            me.bindEvents();


            el.attr('data-initialized', 'true');
            return me;
        },


        /**
         * [bindEvents description]
         * @return {[type]} [description]
         */
        bindEvents: function() {
            var me = this,
                el = me.el;

        },

        initChart: function() {
            var me = this,
                el = me.el,
                option;


            comChart = echarts.init(el[0], me.options.theme);
            var labelTop = {
                normal: {
                    label: {
                        show: true,
                        position: 'center',
                        formatter: '{b}',
                        textStyle: {
                            baseline: 'bottom'
                        }
                    },
                    labelLine: {
                        show: false
                    }
                }
            };
            var labelFromatter = {
                normal: {
                    label: {
                        formatter: function(params) {
                            return params.percent + '%(' + params.value + ')';
                        },
                        textStyle: {
                            baseline: 'top'
                        }
                    }
                },
            };
            var labelBottom = {
                normal: {
                    color: '#ccc',
                    label: {
                        show: true,
                        position: 'center'
                    },
                    labelLine: {
                        show: false
                    }
                },
                emphasis: {
                    color: 'rgba(0,0,0,0)'
                }
            };
            var radius = [40, 55];
            option = {
                legend: {
                    x: 'center',
                    y: '0',
                    data: ['舆情指数', '互动指数', '正向指数', '留存量']
                },
                series: [{
                    type: 'pie',
                    center: ['20%', '50%'],
                    radius: radius,
                    x: '0%', // for funnel
                    itemStyle: labelFromatter,
                    data: [{
                        name: 'other',
                        value: 2462,
                        itemStyle: labelBottom
                    }, {
                        name: '舆情指数',
                        value: 5489,
                        itemStyle: labelTop
                    }]
                }, {
                    type: 'pie',
                    center: ['40%', '50%'],
                    radius: radius,
                    x: '25%', // for funnel
                    itemStyle: labelFromatter,
                    data: [{
                        name: 'other',
                        value: 656,
                        itemStyle: labelBottom
                    }, {
                        name: '互动指数',
                        value: 1238,
                        itemStyle: labelTop
                    }]
                }, {
                    type: 'pie',
                    center: ['60%', '50%'],
                    radius: radius,
                    x: '50%', // for funnel
                    itemStyle: labelFromatter,
                    data: [{
                        name: 'other',
                        value: 2567,
                        itemStyle: labelBottom
                    }, {
                        name: '正向指数',
                        value: 1529,
                        itemStyle: labelTop
                    }]
                }, {
                    type: 'pie',
                    center: ['80%', '50%'],
                    radius: radius,
                    x: '75%', // for funnel
                    itemStyle: labelFromatter,
                    data: [{
                        name: 'other',
                        value: 209,
                        itemStyle: labelBottom
                    }, {
                        name: '留存量',
                        value: 1301,
                        itemStyle: labelTop
                    }]
                }]
            };

            comChart.setOption(option);
        }
    }

    $.fn.SNSExponent = function(opts) {
        var me = this,
            el = me.el,
            comSNSExponent;

        // 如果没有被初始化过
        if (!(el && el.length && el.attr('data-initialized') != 'true')) {
            comSNSExponent = new SNSExponent(this, opts);
        }

        return comSNSExponent.init();
    }
})(jQuery, window, document);
